﻿@model FieldControlViewModel
@{ 
	string ctlID = Model.Prefix + Model.FieldName;
	string dataSource = (!string.IsNullOrEmpty(Model.Settings[0])) ? Model.Settings[0] : string.Empty;
	string selectItem = string.Empty;
	foreach (var item in StringHelper.GetArrayBySplit<string>(dataSource, "|"))
	{
		selectItem += "<option value='" + item + "'>" + item + "</option>";
	}
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\" ";
	}
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\"" + Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
}
<select class="layui-input" name="@{@ctlID}EditableSelect" id="@{@ctlID}EditableSelect" placeholder="可选择或填写" lay-ignore>@Html.Raw(selectItem)</select>
<table class="layui-table">
	<thead>
		<tr>
			<th>已选项</th>
			<th>图片</th>
			<th style="width:70px;">操作</th>
		</tr>
	</thead>
	<tbody id="tbody@{@ctlID}">
	</tbody>
</table>
<span class="layui-bg-green">@Model.Description</span>
<span style="color:red;" @Html.Raw(dataValMsg)></span>
<input type="hidden" name="@{@ctlID}" id="@{@ctlID}" value="@Model.FieldValue" @Html.Raw(dataVal) />
<script type="text/javascript">
	jQuery(function () {
		initEditableSelect("@{@ctlID}EditableSelect");
		$('#@{@ctlID}EditableSelect').blur(function () {
			var item = $(this).val();
			if (!item || item == "") return;
			item = item + "$";
			AddProductStyleItem(item,"tbody@{@ctlID}","@{@ctlID}");
		});
		ShowProductStyleSelect("tbody@{@ctlID}","@{@ctlID}");
	});
</script>